﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Data.SqlClient;
using Jungle.Code.DAL;

namespace Jungle.Code.Core
{
	public class Language
	{
		#region Fields
		private int _langID;
		private string _name;
		private string _sysName;
		private bool _enabled;
		private int _ord;
		#endregion

		#region Properties
		public int LangID {
			get {
				return _langID;
			}
			set {
				_langID = value;
			}
		}
		public string Name {
			get {
				return _name;
			}
			set {
				_name = value;
			}
		}
		public string SysName {
			get {
				return _sysName;
			}
			set {
				_sysName = value;
			}
		}
		public bool Enabled {
			get {
				return _enabled;
			}
			set {
				_enabled = value;
			}
		}
		public int Ord {
			get {
				return _ord;
			}
			set {
				_ord = value;
			}
		}
		#endregion

		public Language(int langID, string name, string sysName, bool enabled, int ord) {
			LangID = langID;
			Name = name;
			SysName = sysName;
			Enabled = enabled;
			Ord = ord;
		}

		public static List<Language> GetAllLanguages() {
			List<Language> langs = new List<Language>();
			SqlConnection conn = new SqlConnection(DBHelper.ConnectionString);
			using (SqlCommand command = new SqlCommand("dbo.crLanguages_GetAll", conn)) {
				command.CommandType = CommandType.StoredProcedure;
				conn.Open();
				SqlDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection);
				if (dr.HasRows) {
					while (dr.Read()) {
						Language lang = new Language((int)dr["langID"], (string)dr["name"], (string)dr["sysName"], (bool)dr["enabled"], (int)dr["ord"]);
						langs.Add(lang);
					}
				}
				dr.Close();

			}
			return langs;
		}
	}
}
